package com.example.aopweaver.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

@EnableAspectJAutoProxy
@Aspect
@Component
public class AnnotationPointcut {

    /**
     *
     * ！！！单独添加
     * 给添加了 指定的自定义注解 AnnotationLog 的方法添加切面
     */
    @Pointcut(value="@annotation(com.example.aopweaver.aspect.AnnotationLog)")
    private void aspect(){}

    @Before(value = "aspect()")
    public void beforeDefine() {
        System.out.println("===========1、beforeDefine===========");
    }

    /**
     * ！！！批量添加
     * 给多个方法插入 切入点
     */
    @After("execution(* com.example.aopweaver.service.UserServiceImpl.*(..))")
    public void afterDefine() {
        System.out.println("===========2、afterDefine===========");
    }



    //环绕切点方法执行
    @Around(value = "aspect()")
    public Object Around(JoinPoint joinPoint) throws Throwable {
        System.out.println("===========Around环绕前======="+joinPoint);
        ((ProceedingJoinPoint)joinPoint).proceed();
        System.out.println("===========Around环绕后======="+joinPoint);
        return null;
    }

}
